package com.sky.controller.user;

import com.sky.dto.CategoryPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.dto.PageDto;
import com.sky.result.PageBean;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.DishVO;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Select;
import org.bouncycastle.jcajce.provider.symmetric.util.PBE;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RestController("userOrderController")
@RequestMapping("/user/order")
@Slf4j
@Api(tags = "C端-订单接口")
public class OrderController {
    @Autowired
    OrderService orderService;

    /**
     * 订单的提交功能
     */
    @PostMapping("/submit")
    public Result<OrderSubmitVO> submitVOResult(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
        log.info("订单的提交{}", ordersSubmitDTO);
        OrderSubmitVO orderSubmitVO = orderService.submitOrder(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }
    /**
     * 历史订单查询
     */
    @GetMapping("/historyOrders")
    public Result historyOrders(PageDto pageDto){
        log.info("历史订单分页查询{}",pageDto );
        PageBean<OrderVO> orderVOPageBean= orderService.selectHistory(pageDto);
        return Result.success(orderVOPageBean);
    }
    /**
     * 查询订单详情·
     */
    @GetMapping("/orderDetail/{id}")
    public Result selectDetails(@PathVariable Long id){
        log.info("查询订单详情{}",id );
        OrderVO orderVO=orderService.selectDatails(id);
        return Result.success(orderVO);
    }
    /**
     * 取消订单
     */
    @PutMapping("/cancel/{id}")
    public Result cancelOrder(@PathVariable Long id){

        log.info("取消订单{}",id );
        orderService.cancelOrder(id);
        return Result.success();

    }
    /**
     * 再来一单
     */
    @PostMapping("/repetition/{id}")
    public Result againOne(@PathVariable Long id){
        log.info("再来一单{}", id);
        orderService.againOne(id);
        return Result.success();
    }


//    /**
//     * 订单支付
//     *
//     * @param ordersPaymentDTO
//     * @return
//     */
//    @PutMapping("/payment")
//    @ApiOperation("订单支付")
//    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
//        log.info("订单支付：{}", ordersPaymentDTO);
//        OrderPaymentVO orderPaymentVO = orderService.payment(ordersPaymentDTO);
//        log.info("生成预支付交易单：{}", orderPaymentVO);
//        return Result.success(orderPaymentVO);
//    }
    /**
     * 小程序催单
     */
    @GetMapping("/reminder/{id}")
    @ApiOperation("用户催单")
    public Result reminder(@PathVariable Long id){
        log.info("用户催单{}", id);
        orderService.reminder(id);
        return Result.success();

    }
    /**
     * 用户支付
     */
    @PutMapping("/payment")
    @SneakyThrows
    public Result payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO){
        OrderPaymentVO payment = orderService.payment(ordersPaymentDTO);
        return Result.success(payment);
    }


}